<template>
  <!-- 职位管理 -->
  <div>
    <!-- 搜索容器 -->
    <div class="search-container">
      <!-- 行业输入框 -->
      <span class="search-label">行业：</span>
      <el-input 
        v-model="typeName" 
        placeholder="搜索行业" 
        class="search-input search-industry"
        clearable>
      </el-input>

      <!-- 职位输入框 -->
      <span class="search-label">职位：</span>
      <el-input 
        v-model="jobName" 
        placeholder="搜索职位" 
        class="search-input"
        clearable>
      </el-input>
      
      <!-- 状态下拉框（仅启用和禁用） -->
      <span class="search-label">状态：</span>
      <el-select v-model="jobStatus" placeholder="请选择状态" class="search-select">
        <el-option label="启用" value="enable"></el-option>
        <el-option label="禁用" value="disable"></el-option>
      </el-select>

      <el-button type="primary" class="search-button">查询</el-button>
      <el-button type="success" class="search-button">重置</el-button>
      <el-button type="success" class="search-button">添加职位</el-button>
    </div>

    <el-table :data="tableData" border style="width: 100%; margin-top: 15px;" 
      :header-cell-style="{ textAlign: 'center' }"
      :cell-style="{ textAlign: 'center' }">
      <!-- 第一列：行业 -->
      <el-table-column prop="industry" label="行业"></el-table-column>
      
      <!-- 第二列：职位 -->
      <el-table-column prop="position" label="职位"></el-table-column>
      
      <!-- 第三列：职位简介 -->
      <el-table-column prop="description" label="职位简介"></el-table-column>
      
      <!-- 第四列：状态列 -->
      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status === 'enable' ? 'success' : 'danger'">
            {{ scope.row.status === 'enable' ? '启用' : '禁用' }}
          </el-tag>
        </template>
      </el-table-column>
      
      <!-- 第五列：职位操作 -->
      <el-table-column label="职位操作" width="260">
        <template slot-scope="scope">
          <el-button @click="handleEdit(scope.row)" type="text" size="small">修改职位</el-button>
          <el-button @click="handleDelete(scope.row)" type="text" size="small">删除职位</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination class="pagination-left" background layout="prev, pager, next" :total="1000"></el-pagination>
  </div>
</template>

<script>
export default {
  methods: {
    handleEdit(row) {
      console.log('编辑', row);
    },
    handleDelete(row) {
      console.log('删除', row);
    },

    // 加载数据方法（接收查询条件参数）
    async loadData(params) {
      try {
        // 调用后端接口并传递查询条件
        const response = await selectByHr(params);
        console.log("完整响应:", response);

        // 假设接口返回的数据在response.data中
        this.tableData = response.data || [];
      } catch (error) {
        console.error("数据加载失败:", error);
        this.$message.error("加载数据失败，请稍后重试");
      }
    },
    
  },
  data() {
    return {
      typeName: '',         // 行业搜索输入
      jobName: '',          // 职位搜索输入
      jobStatus: '',         // 选择的状态（默认空字符串）
      tableData: []
    }
  },

    created() {
    // 页面初始化时加载数据（默认无查询条件）
    this.loadData({});
  },
}
</script>

<style scoped>
.search-container {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 0;
}

.search-label {
  white-space: nowrap;
  font-size: 14px;
  color: #606266;
  margin-right: 0;
}

.search-input {
  width: 160px;
  margin-right: 8px;
}

.search-select {
  width: 160px;
  margin-right: 8px;
}

.search-button {
  margin-left: 8px;
}

.el-table th {
  height: 70px !important;
  line-height: 70px !important;
}

.el-table {
  margin-top: 15px;
}

.el-table__header-wrapper th {
  background-color: #f5f7fa;
}

.pagination-left {
  margin-top: 15px;
  text-align: left;
}

.el-table .el-button--text {
  margin: 0 5px;
}
</style>